package com.solution.admin.home.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import com.solution.admin.auth.entity.TodoEntity;
import com.solution.admin.home.dao.IndexDao;
import com.solution.admin.home.entity.SiteConfigItemEntity;
import com.solution.admin.home.entity.SiteModuleEntity;
import com.solution.admin.product.entity.ProductCategoryEntity;
import com.solution.common.dao.impl.BaseDaoImpl;

/**
 * PC首页查询缓存
 * @author llp
 */
@Repository
public class IndexDaoImpl  extends BaseDaoImpl<TodoEntity> implements IndexDao {
	
	@Autowired
	private RedisTemplate redisTemplate;

	/**
	 * 查询首页主屏幕广告图片信息 （查询redis）
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<SiteConfigItemEntity> listIndexRollingAD(Map<String, Object> param){
		String key = (String)param.get("key");
		List<SiteConfigItemEntity>  sciList = (List<SiteConfigItemEntity>)redisTemplate.opsForValue().get(key);
		return sciList;
	}

	/**
	 * 查询首页商品类型 （查询redis）
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<ProductCategoryEntity> listIndexProductCategory(Map<String, Object> param){
		String key = (String)param.get("key");
		List<ProductCategoryEntity>  pcList = (List<ProductCategoryEntity>)redisTemplate.opsForValue().get(key);
		return pcList;
	}

	/**
	 * 查询首页楼层信息
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Map<String, List<SiteConfigItemEntity>> listIndexProductFloor(Map<String, Object> param){
		String key = (String)param.get("key");
		Map<String, List<SiteConfigItemEntity>>  sciMap = (Map<String, List<SiteConfigItemEntity>>)redisTemplate.opsForValue().get(key);
		return sciMap;
	}

	/**
	 * 查询首页品牌馆信息
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<SiteConfigItemEntity> listIndexBrandLibrary(Map<String, Object> param){
		String key = (String)param.get("key");
		List<SiteConfigItemEntity>  sciList = (List<SiteConfigItemEntity>)redisTemplate.opsForValue().get(key);
		return sciList;
	}

	
	/**
	 * 查询首页底部指南信息
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Map<String, List<SiteConfigItemEntity>> listIndexFingerPost(Map<String, Object> param){
		String key = (String)param.get("key");
		Map<String, List<SiteConfigItemEntity>>  sciMap = (Map<String, List<SiteConfigItemEntity>>)redisTemplate.opsForValue().get(key);
		return sciMap;
	}
	
	/**
	 * 将数据保存到redis中
	 * @param key
	 * @param data
	 */
	@SuppressWarnings("unchecked")
	public void saveDataToRedis(String key , Object data){
		redisTemplate.opsForValue().set(key, data);
	}
	
	/**
	 * 将网站指南信息保存到redis中
	 * @param key
	 * @param data
	 */
	@SuppressWarnings("unchecked")
	public void saveFingerMapDataToRedis(String key, Map<String, List<SiteConfigItemEntity>> data){
		redisTemplate.opsForHash().putAll(key, data);
	}
	
	/**
	 * 保存楼层信息到redis 中
	 * @param key
	 * @param smMap
	 */
	@SuppressWarnings("unchecked")
	public void saveFloorMapDataToRedis(String key, Map<String, SiteModuleEntity> smMap){
		redisTemplate.opsForHash().putAll(key, smMap);
	}
	
	/**
	 * 从redis 查询网站模块列表
	 * @param param
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, SiteModuleEntity> listSiteModule(Map<String, Object> param){
		String key = (String)param.get("key");
		Map<String, SiteModuleEntity>  scMap = (Map<String, SiteModuleEntity>)redisTemplate.opsForValue().get(key);
		return scMap;
	}
	
	/**
	 * 从redis中查询普通配置对象(SiteConfig)
	 * @param param
	 * @return
	 */
	public List<SiteConfigItemEntity> listIndexConfigItem(Map<String, Object> param){
		String key = (String)param.get("key");
		List<SiteConfigItemEntity>  sciList = (List<SiteConfigItemEntity>)redisTemplate.opsForValue().get(key);
		return sciList;
	}
	
	/**
	 * 查询待办事项
	 * @param tparam
	 * @return
	 */
	public List<TodoEntity> listTodoList(Map<String, Object> tparam){
		return getSessionTemplate().selectList(getStatement("listTodoList"), tparam);
	}
	
	/**
	 * 查询微信端我的订单待办事项
	 * @param tparam
	 * @return
	 */
	public List<TodoEntity> listWXTodoList(Map<String, Object> tparam){
		return getSessionTemplate().selectList(getStatement("listWXTodoList"), tparam);
	}

}
